//
//  NSString+ZZZCategory.m
//  zjhealth
//
//  Created by 张润东 on 2017/11/30.
//  Copyright © 2017年 amu. All rights reserved.
//

#import "NSString+ZZZCategory.h"

@implementation NSString (ZZZCategory)

+(NSMutableAttributedString*)attribute:(NSString*)string andColerStr:(NSArray*)colorStringArray andColor:(UIColor*)color andFontString:(NSString*)fontString andFont:(UIFont*)font{
    
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc]initWithString:string];
    if (colorStringArray.count) {
        for (NSString * cstring in colorStringArray) {
            [attStr addAttribute:NSForegroundColorAttributeName value:color range:[string rangeOfString:cstring]];
        }
    }
    if (fontString!=nil) {
        
        [attStr addAttribute:NSFontAttributeName value:font range:[string rangeOfString:fontString]];
    }
    return attStr;
}


//..判断字符串是否为空字符的方法
+ (BOOL)isBlankString:(id)string{
    if (![string isKindOfClass:[NSString class]]) {
        return YES;
    }
    NSString * str = (NSString*)string;
    if((NSNull *)str == [NSNull null]){
        return YES;
    }
    if (str == nil || str == NULL || [str isKindOfClass:[NSNull class]] ||[str isEqualToString:@"(null)"] || [str isEqualToString:@"<null>"]) {
        return YES;
    }
    if ([[str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0) {
        return YES;
    }
    str = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    str = [str stringByReplacingOccurrencesOfString:@"\r" withString:@""];
    str = [str stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    if (str.length <= 0) {
        return YES;
    }
    return NO;
}

#pragma mark -  判断字符串是否为空,为空的话返回 某字符串 （一般用于保存字典时）
+ (NSString *)getString:(NSString *)string nullString:(NSString *)placeString{
    string=[NSString stringWithFormat:@"%@",string];
    if ([NSString isBlankString:string]) {
        return placeString?placeString:@"";
    }
    return string;
}

+ (NSString *)getString:(NSString *)string andNullString:(NSString *)placeString{
    string=[NSString stringWithFormat:@"%@",string];
    if ([NSString isBlankString:string]) {
        return placeString?placeString:@"";
    }
    return string;
}

+(NSString *)IsNotNull:(id)string {
    string=[NSString stringWithFormat:@"%@",string];
    return [NSString isBlankString:string]?@"":string;
}

@end
